#include <iostream>
#include <unordered_map>
#include <cmath>
#include <algorithm>
using namespace std;
std::unordered_map<char, int> h;
int main() {
    for(int i = 0; i <= 9; i++) {
        h['0' + i] = i;
    }
    h['A'] = 10;
    h['B'] = 11;
    h['C'] = 12;
    h['D'] = 13;
    h['E'] = 14;
    h['F'] = 15;
    int n, m;
    string s;
    string ret = "";
    cin >> n;
    cin >> s;
    cin >> m;
    int k = 0; 
    int temp = 0;
    for(int i = s.size() - 1; i >= 0; i--) {
        int t = h[s[i]];
        temp += t * pow(n, k++);
    }
    while(temp) {
        int x = temp % m;
        ret += (x + '0') <= '9' ? (x + '0') : (x - 10 + 'A');
        temp /= m;
    }
    reverse(ret.begin(), ret.end());
    cout << ret << endl;
    return 0;
}